﻿#pragma once

#include "../MirEnvir/Envir.h"
#include "QuestInfo.h"
#include "../../Shared/Data/ItemData.h"
#include "MonsterInfo.h"
#include "../../Shared/Data/ClientData.h"
#include <string>
#include <vector>
#include "../../stringhelper.h"

using namespace Server::MirObjects;
using namespace Server::MirEnvir;

namespace Server::MirDatabase
{
    class QuestProgressInfo
    {
    public:
        virtual ~QuestProgressInfo()
        {
            delete Info;
        }

    protected:
        static Server::MirEnvir::Envir *getEnvir();

    public:
        int Index = 0;

        QuestInfo *Info;

        DateTime StartDateTime = DateTime::MinValue;
        DateTime EndDateTime = DateTime::MaxValue;

        std::vector<int> KillTaskCount = std::vector<int>();
        std::vector<long long> ItemTaskCount = std::vector<long long>();
        std::vector<bool> FlagTaskSet = std::vector<bool>();

        std::vector<std::string> TaskList = std::vector<std::string>();

        bool getTaken() const;

        bool getCompleted() const;

        bool getNew() const;

        QuestProgressInfo(int index);

        QuestProgressInfo(BinaryReader *reader);

        void Save(BinaryWriter *writer);

        void ResyncTasks();

        bool CheckCompleted();

        #pragma region Need Requirement

        bool NeedItem(ItemInfo *iInfo);

        bool NeedKill(MonsterInfo *mInfo);

        bool NeedFlag(int flagNumber);

        #pragma endregion

        #pragma region Process Quest Task

        void ProcessKill(MonsterInfo *mInfo);

        void ProcessItem(std::vector<UserItem*> &inventory);

        void ProcessFlag(std::vector<bool> &Flags);

        #pragma endregion

        #pragma region Update Task Messages

        void UpdateTasks();

        void UpdateKillTasks();

        void UpdateItemTasks();

        void UpdateFlagTasks();

        void UpdateGotoTask();

        #pragma endregion

        ClientQuestProgress *CreateClientQuestProgress();
    };
}
